const express=require('express')
const cors=require('cors')
let app=express()
app.listen(3000,()=>{
    console.log('3000ok');
})

const query=require("./tools/db")


app.use(express.urlencoded({extended:true}))
app.use(express.json())
app.use(cors())


app.post("/username",async (req,res)=>{

    let  {username}=req.body


    let sql=`select *  from user where username="${username}"`
    let [err,results]=await query(sql)
    // console.log(err,results);
    if(err){
        res.send({
            status:500,
            msg:"用户名请求失败"
        })
        return
    }

    if(results.length>0){
        res.send({
            status:500,
            msg:"用户名已被占用"
        })
        return
    }


    res.send({
        status:200,
        msg:"用户名可以注册"
    })

})